<template>
  <!--会签管理-弹窗-->
  <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk" @cancel="handleCancel"
    okText="提交">
    <template v-if="pageType === 'history'">
      <div v-if="list && list.length>0">
        <a-tabs type="card" @change="callback">
          <a-tab-pane v-for="(item,index) in list" :key="index+1" :tab="'第'+(index+1)+'次审批'">
            <template v-if="receiptsModel === '2'">
              <cailiao-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item" :billsTemplateName="billsTemplateName"
              :pageType="pageType"></cailiao-form>
            </template>
            <template v-else-if="receiptsModel === '3'">
              <laowu-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item" :billsTemplateName="billsTemplateName"
              :pageType="pageType"></laowu-form>
            </template>
            <template v-else-if="receiptsModel === '4'">
              <jihua-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item" :billsTemplateName="billsTemplateName"
              :pageType="pageType"></jihua-form>
            </template>
            <template v-else-if="receiptsModel === '1'">
              <shenqing-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item" :billsTemplateName="billsTemplateName"
              :pageType="pageType"></shenqing-form>
            </template>
            <template v-else-if="receiptsModel === '5'">
              <xmht-form ref="realForm2" :disabled="disableSubmit" :defaultModel="item" :billsTemplateName="billsTemplateName"
              :pageType="pageType"></xmht-form>
            </template>
            <template v-else-if="receiptsModel === '6' || receiptsModel === '7' || receiptsModel === '8' || receiptsModel === '9'">
              <wzzc-form  ref="realForm2" :disabled="disableSubmit" :defaultModel="item"
              :pageType="pageType" :billsTemplateName="billsTemplateName" :receiptsModel="receiptsModel"></wzzc-form>
            </template>
          </a-tab-pane>
        </a-tabs>
      </div>
      <div v-else style="height:400px">暂无审核记录</div>
    </template>
    <template v-else>
      <template v-if="pageType === 'anew'">
        <a-tabs type="card" @change="callback">
          <a-tab-pane key="1" tab="重新提交">
            <template v-if="receiptsModel === '2'">
              <cailiao-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
                :pageType="pageType"></cailiao-form>
            </template>
            <template v-else-if="receiptsModel === '3'"> 
              <laowu-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
                :pageType="pageType"></laowu-form>
            </template>
            <template v-else-if="receiptsModel === '4'">
              <jihua-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
                :pageType="pageType"></jihua-form>
            </template>
            <template v-else-if="receiptsModel === '1'">
              <shenqing-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
                :pageType="pageType"></shenqing-form>
            </template>
            <template v-else-if="receiptsModel === '5'">
              <xmht-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"></xmht-form>
            </template>
            <template v-else-if="receiptsModel === '6' || receiptsModel === '7' || receiptsModel === '8' || receiptsModel === '9'">
              <wzzc-form   ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName" :receiptsModel="receiptsModel"></wzzc-form>
            </template>
          </a-tab-pane>
          <a-tab-pane key="2" tab="查看上次审核记录">
            <template v-if="receiptsModel === '2'">
              <cailiao-form ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName"></cailiao-form>
            </template>
            <template v-else-if="receiptsModel === '3'">
              <laowu-form ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName"></laowu-form>
            </template>
            <template v-else-if="receiptsModel === '4'">
              <jihua-form ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName"></jihua-form>
            </template>
            <template v-else-if="receiptsModel === '1'">
              <shenqing-form ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName"></shenqing-form>
            </template>
            <template v-else-if="receiptsModel === '5'">
              <xmht-form ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName"></xmht-form>
            </template>
            <template v-else-if="receiptsModel === '6' || receiptsModel === '7' || receiptsModel === '8' || receiptsModel === '9'">
              <wzzc-form  ref="realForm2" :disabled="disableSubmit2" pageType="detail" :billsTemplateName="billsTemplateName" :receiptsModel="receiptsModel"></wzzc-form>
            </template>
          </a-tab-pane>
        </a-tabs>
      </template>
      <template v-else-if="pageType === 'approver'">
        <template v-if="receiptsModel === '2'">
          <cailiao-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"
            @handleOpen="handleOpen"></cailiao-form>
        </template>
        <template v-else-if="receiptsModel === '3'">
          <laowu-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"
            @handleOpen="handleOpen"></laowu-form>
        </template>
        <template v-else-if="receiptsModel === '4'">
          <jihua-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"
            @handleOpen="handleOpen"></jihua-form>
        </template>
        <template v-else-if="receiptsModel === '1'">
          <shenqing-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"
            @handleOpen="handleOpen"></shenqing-form>
        </template>
        <template v-else-if="receiptsModel === '5'">
          <xmht-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"
            @handleOpen="handleOpen"></xmht-form>
        </template>
        <template v-else-if="receiptsModel === '6' || receiptsModel === '7' || receiptsModel === '8' || receiptsModel === '9'">
          <wzzc-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType"
            @handleOpen="handleOpen" :billsTemplateName="billsTemplateName" :receiptsModel="receiptsModel"></wzzc-form>
        </template>
      </template>
      <template v-else>
        <template v-if="receiptsModel === '2'">
          <cailiao-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
            :pageType="pageType"></cailiao-form>
        </template>
        <template v-else-if="receiptsModel === '3'">
          <laowu-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"></laowu-form>
        </template>
        <template v-else-if="receiptsModel === '4'">
          <jihua-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"></jihua-form>
        </template>
        <template v-else-if="receiptsModel === '1'">
          <shenqing-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :billsTemplateName="billsTemplateName"
            :pageType="pageType"></shenqing-form>
        </template>
        <template v-else-if="receiptsModel === '5'">
          <xmht-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName"></xmht-form>
        </template>
        <template v-else-if="receiptsModel === '6' || receiptsModel === '7' || receiptsModel === '8' || receiptsModel === '9'">
          <wzzc-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :pageType="pageType" :billsTemplateName="billsTemplateName" :receiptsModel="receiptsModel"></wzzc-form>
        </template>
      </template>
    </template>
    <template #footer>
      <a-button key="back" v-if="pageType === 'add' || pageType === 'edit' || pageType === 'anew' || pageType === 'approver'" @click="handleCancel">取消</a-button>
      <a-popconfirm title="确定保存吗？" @confirm="handleSave">
        <a-button v-if="pageType === 'add' || pageType === 'edit'" key="save" type="primary">保存</a-button>
      </a-popconfirm>
      <a-popconfirm title="确定提交吗？" @confirm="handleOk">
        <a-button v-if="pageType === 'anew' || pageType === 'edit'" key="submit" type="primary"
          style="margin-left: 8px;">提交</a-button>
      </a-popconfirm>
      <a-popconfirm title="确定提交审核吗？" @confirm="handleOk">
        <a-button v-if="pageType === 'add'" key="submit" type="primary" style="margin-left: 8px;">提交审核</a-button>
      </a-popconfirm>
      <a-popconfirm v-if="!(pageType === 'approver'?false:true)" title="确定驳回吗？" @confirm="handleReject">
        <a-button key="reject" type="primary"
          style="background: red;color: white;border: 1px solid red;margin-left: 8px;">驳回</a-button>
      </a-popconfirm>
      <a-popconfirm v-if="!(pageType === 'approver'?false:true)" title="确定同意吗？" @confirm="handleAgree">
        <a-button key="submit" type="primary">同意</a-button>
      </a-popconfirm>
    </template>
  </j-modal>
</template>
<script>
  import cailiaoForm from './cailiaoForm';
  import laowuForm from './laowuForm';
  import jihuaForm from './jihuaForm';
  import shenqingForm from './shenqingForm';
  import xmhtForm from './xmhtForm';
  import wzzcForm from './wzzcForm';
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  export default {
    name: 'WtShenpiModal',
    components: {
      cailiaoForm,laowuForm,jihuaForm,shenqingForm,xmhtForm,wzzcForm
    },
    props: {

    },
    data() {
      return {
        title: '',
        width: 1000,
        visible: false,
        disableSubmit: false,
        disableSubmit2: false,
        privacyDialogShow: false,
        objdata: {},
        pageType: '', //add-新增 anew-重复提交 edit-编辑 detail-详情 approver-审批 history-历史记录
        billsTemplateName: '',
        receiptsModel:'', //1-付款申请 2-材料结算 3-劳务结算 4-付款计划 5-工程项目合同审批 6-线下班组招采询价 7-线下物资招采询价 8-平台班组招采询价 9-平台物资招采询价
        list: [],
      }
    },
    methods: {
      retrieve(record,type){
      	let ret = false;
      	if(record.indexOf(type) != -1){
      		ret = true;
      	}else{
      		ret = false;
      	}
      	return ret
      },
      callback(e) {
        console.log(1, e)
        if (e === '2') {
          this.$nextTick(() => {
            this.$refs.realForm2.edit(this.objdata);
            this.disableSubmit2 = true;
          })
        }
      },
      add(record,objlist) {
        console.log('弹窗add', record);
        this.visible = true
        this.$nextTick(() => {
          this.$refs.realForm.add(record);
        })
        this.$forceUpdate();
      },
      edit(record) {
        let that = this;
        this.objdata = record;
        this.visible = true;
        if (this.pageType === 'history') {
          this.getHistoryData(record);
        } else {
          this.$nextTick(() => {
            this.$refs.realForm.edit(record);
          })
        }
        this.$forceUpdate();
      },
      //获取历史记录
      getHistoryData(record) {
        var that = this;
        if (this.receiptsModel === '2') {
          getAction(`/wtCountersign/countersignMaterialStatement/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }else if(this.receiptsModel === '3'){
          getAction(`/countersign/wtCountersignServiceSettlement/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }else if(this.receiptsModel === '4'){
          getAction(`/countersign/wtCountersignPaymentPlan/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }else if(this.receiptsModel === '1'){
          getAction(`/countersign/wtCountersignPaymentRequest/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }else if(this.receiptsModel === '5'){
          getAction(`/countersign/wtCountersignProjectContract/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }else if(this.receiptsModel === '6' || this.receiptsModel === '7' || this.receiptsModel === '8' || this.receiptsModel === '9'){ 
          getAction(`/countersign/wtCountersignBidding/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        }
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        this.$refs.realForm.submitForm('1');
      },
      handleSave() {
        this.$refs.realForm.submitForm('0')
      },
      //驳回
      handleReject() {
        this.$refs.realForm.submitForm('3');
      },
      //同意
      handleAgree() {
        this.$refs.realForm.submitForm('2');
      },
      submitCallback() {
        this.$emit('ok');
        this.visible = false;
      },
      //查看原审核记录
      handleOpen(type) {
        this.$emit('handleOpen', type);
      },
      handleCancel() {
        this.close()
      },
    },
  }
</script>